<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        const p1 = () =>{
            return new Promise((resolve,reject) =>{
                setTimeout(() => {
                    console.log('p1触发了');
                    resolve('a')
                }, 1000)
            })
        }
        const p2 = () =>{
            return new Promise((resolve,reject) =>{
                setTimeout(() => {
                    console.log('p2触发了');
                    resolve('b')
                }, 500)
            })
        }
        const p3 = () =>{
            return new Promise((resolve,reject) =>{
                setTimeout(() => {
                    console.log('p3触发了');
                    resolve('c')
                }, 1500)
            })
        }
        p1()
          .then((res) => {
            console.log('res',res);//a
            return p2()
          })
          .then((res) => {
            console.log('res',res);//b
            return p3()
          })
          .then((res) => {
            console.log('res',res);//c
          }).catch(err =>{
            console.log(err);
          })

          const test = async () => {
            await p1 ()
            await p2 ()
            await p3 ()
          }
          test().catch(err =>{
            console.log(err);
          })

          const test1 = async () => {
            try{           
            await p1 ()
            await p2 ()
            await p3 ()
          } catch (error) {
            console.log(error);
          }
          }
          test()

          //直接中断
          const test2 = async () => {
            const count = 4
            await p1()
            if(count >5){
                await p2()
            }else{
                return
            }
            await p3()
          }
          test()
 
    </script>
</body>
</html>